package com.qdsgjsfk.vision.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import com.qdsgjsfk.vision.R;

import com.qdsgjsfk.vision.base.BaseActivity;
import com.qdsgjsfk.vision.util.NetUtil;
import com.rest.business.RestProxy;
import com.rest.response.StudentInfoResponse;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by HP on 2019/11/28.
 */

public class FaceDetectorInfoActivity extends BaseActivity {
    @BindView(R.id.tv_name)
    TextView tv_name;
    String studentId;
    String studentName,taskId;

    @Override
    protected void initViews() {
        tv_name.setText(getIntent().getStringExtra("studentName"));
        studentName = getIntent().getStringExtra("studentName");
        studentId = getIntent().getStringExtra("studentId");
        taskId = getIntent().getStringExtra("taskId");
        if(TextUtils.isEmpty(studentName)){
            getStudentInfo();
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_face_detector_info;
    }

    @OnClick(R.id.btn_confirm)
    void btn_confirm() {
        Bundle bundle = new Bundle();
        bundle.putString("studentId", studentId);
        bundle.putString("studentName",studentName);
        bundle.putInt("faceType",0);
        startActivity( FaceDetectorActivity.class, bundle);
        finish();
    }

    @OnClick(R.id.btn_add_face)
    void btn_add_face() {
        Bundle bundle = new Bundle();
        bundle.putString("studentId", studentId);
        bundle.putString("studentName",studentName);
        bundle.putInt("faceType",0);
        startActivity( FaceDetectorActivity.class, bundle);
        finish();
    }


    private void getStudentInfo(){
        RestProxy.getInstance().getStudentInfo(taskId, studentId, new Observer<StudentInfoResponse>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(StudentInfoResponse studentInfoResponse) {
                tv_name.setText(studentInfoResponse.data.studentName);
            }

            @Override
            public void onError(Throwable e) {
                NetUtil.onError(e, FaceDetectorInfoActivity.this);
                finish();
            }

            @Override
            public void onComplete() {

            }
        });
    }
}
